/*
 * acm2851.c
 *
 *  Created on: 6 Apr 2010
 *      Author: xuxu
 */

#include<stdio.h>
#include<string.h>
int main()
{
	char str[1000];
	int n,len,contab,conspace;
	int i;
	int bo;
	scanf("%d",&n);
	while(n--)
	{
		contab=0;
		conspace=0;
		bo=0;
		while(1)
		{
			i=0;
			while(scanf("%c",&str[i])&&str[i]!='\n')
				i++;
			str[i]=0;
			if(!strcmp(str,"##"))
			{
				printf("%d tab(s) replaced\n",contab);
				printf("%d trailing space(s) removed\n",conspace);
				break;
			}
			len=strlen(str);
			bo=0;
			for(i=len-1;i>=0;i--)
			{
				while(!bo&&i>=0&&(str[i]==' '||str[i]=='\t'))
				{
					if(' '==str[i])
						conspace++;
					else if('\t'==str[i])
					{
						contab++;
						conspace+=4;
					}
					i--;
				}
				bo=1;
				if('\t'==str[i])
					contab++;
			}
		}
	}
	return 0;
}
